package recharge

import (
	"AI/sql/disposition"
	status "AI/util"
	"database/sql"
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

type PackageList struct {
	name       string
	money      string
	PayList    string
	types      string
	businessid string
}

func GetPackage(c *gin.Context) {

	sqls := "select * from packagelist"
	db, _ := sql.Open(disposition.Usersql["sqlname"], disposition.Usersql["sqlurl"])
	info, _ := db.Query(sqls)

	cols, _ := info.Columns()
	fmt.Println(cols, 12345689)
	rawResult := make([][]byte, len(cols))
	fmt.Println(rawResult, 12345689)
	var result []interface{}
	dest := make([]interface{}, len(cols))
	values := make([]interface{}, len(cols))

	for i, _ := range rawResult {
		dest[i] = &rawResult[i]
	}
	fmt.Println(len(cols), 12316565)
	num := 0
	for info.Next() {
		infos := make(map[string]interface{})

		err := info.Scan(dest...)
		fmt.Println(dest, err)
		for i, raw := range rawResult {
			if raw == nil {
				values[i] = ""
			} else {
				values[i] = string(raw)
			}
		}
		// fmt.Println(result, 123165615)

		for i := 0; i < len(cols); i++ {
			fmt.Println(values[i], "/n")
			infos[string(cols[i])] = values[i]
		}
		result = append(result, infos)
		num += 1

	}

	c.JSON(http.StatusOK, gin.H{
		"code": status.Exit,
		"msg":  "err",
		"data": result,
	})
	return
}
